# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=quagga
pkgver=1.2.4
pkgrel=9
pkgdesc="A free routing daemon replacing Zebra supporting RIP, OSPF, BGP and NHRP"
url="https://www.nongnu.org/quagga/"
arch="all"
license="GPL-2.0-or-later"
options="!check" # no testsuite
depends="iproute2"
replaces="quagga-nhrp"
provides="quagga-nhrp=$pkgver"
makedepends="linux-headers readline-dev ncurses-dev c-ares-dev net-snmp-dev
	gawk texinfo perl"
install="$pkgname.pre-install $pkgname.post-install $pkgname.post-upgrade"
subpackages="$pkgname-dev $pkgname-doc $pkgname-dbg $pkgname-openrc"
pkgusers="quagga"
pkggroups="quagga"
source="https://github.com/Quagga/quagga/releases/download/quagga-$pkgver/quagga-$pkgver.tar.gz
	0001-nhrpd-change-ipsec-SA-count-to-32-bit.patch
	1001-bgpd-allow-using-ebgp-multihop-for-ibgp-connections.patch
	dont-hook-core-signals.patch

	bgpd.initd
	zebra.initd
	zebra.confd
	"

# secfixes:
#   1.1.1-r0:
#     - CVE-2017-5495

build() {
	quagga_cv_ipforward_method=proc \
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--disable-static \
		--enable-ospf6d \
		--enable-rtadv \
		--enable-user=quagga \
		--enable-group=quagga \
		--enable-vty-group=quagga \
		--enable-vtysh \
		--enable-snmp \
		--enable-multipath=64 \
		--enable-pimd \
		--sysconfdir=/etc/quagga \
		--enable-exampledir=/usr/share/doc/quagga/ \
		--localstatedir=/var/run/quagga

	# add CFLAGS to work around textrel issue
	# adding -fcommon as a workaround for multiple __packed definition
	# same as in Gentoo
	make CFLAGS="$CFLAGS -fcommon -fPIC"
}

package() {
	make DESTDIR="$pkgdir" install

	install -o quagga -g quagga -d "$pkgdir"/var/run/quagga
	for i in zebra bgpd; do
		install -Dm755 "$srcdir"/$i.initd "$pkgdir"/etc/init.d/$i
	done
	for i in ripd ospfd ripngd ospf6d nhrpd; do
		ln -s bgpd "$pkgdir"/etc/init.d/$i
	done
	install -Dm644 "$srcdir/zebra.confd" "$pkgdir"/etc/conf.d/zebra
	install -o quagga -g quagga -d -m755 "$pkgdir"/etc/quagga
}

sha512sums="
3e72440bcccfd3c1a449a62b7ff8623441256399a2bee0a39fa0a19694a5a78ac909c5c2128a24735bc034ea8b0811827293b480a2584a3a4c8ae36be9cf1fcd  quagga-1.2.4.tar.gz
264103030fa8d57e7e7bd8a271b258dd8bae86242e15431060e20827b62de46be6f59617c216161aa7bc141c9e18a5aecbdb342545288340024c40f46c717aa4  0001-nhrpd-change-ipsec-SA-count-to-32-bit.patch
dfa33341119fe51caa7bc33b44256f57361f2e3f8192862cca215b312ceb68e6a8c264dbf2a43d6244e6152bfad110cb0fdbefb065d95dd50389cf613d9720b3  1001-bgpd-allow-using-ebgp-multihop-for-ibgp-connections.patch
5ef5c5e6d70d991b33b13a062e25b6fbde395dceee36aea29384b0640a48d2957ed5f50d416a1f2f770bf69bae2340133e35b1114be7e1fa722eb6d3d021f37a  dont-hook-core-signals.patch
13b5b57e10df013bd2d931abc49bf76b8c4dee59dbceab22c9f151ccb988b2c5f7167f2909027d5e0f990b59da8de115667b02484aee9a67d347625700f6cacd  bgpd.initd
7099135b6e20ad81322e7ec5ec4f0734c0ace60a69c282ad458b9700e39258831ecf29d5eaba0cd0f44bf17004283f17a80c0c1d90e8f407ababe89a75e60850  zebra.initd
900972c6f98e561dfacf384111251db262326e8764b8c763a5ef639fa11c7949c03eef5e3bce324a4b1964fe45416d2db74ae1b6bc967f7d4ba48c2eeda017c4  zebra.confd
"
